#ifndef Event_h
#define Event_h

#include "ObjectPool.h"
#include "String.h"

namespace serika
{
	namespace ut
	{
		class Event
		{
		private:
			Event();
			~Event();

		public:
			static Event* NewEvent();
			static Event* NewEvent(int type, int code);

		public:
			void SetCode(int code) { mCode = code; }
			int GetCode() const { return mCode; }

			void SetType(int type) { mType = type; }
			int GetType() const { return mType; }

			void SetSource(int source) { mSource = source; }
			int GetSource() const { return mSource; }

			void SetTarget(int target) { mTarget = target; }
			int GetTarget() const { return mTarget; }

			void SetSender(const String& sender) { mSender = sender; }
			const String& GetSender() const { return mSender; }

			void SetReceiver(const String& receiver) { mReceiver = receiver; }
			const String& GetReceiver() const { return mReceiver; }

			template<class UserData>
			void SetUserData(UserData* userData);
			template<class UserData>
			UserData* GetUserData() const;

			void Release();
			void Reset();

		private:
			int mType;
			int mCode;

			int mSource;
			int mTarget;
			String mSender;
			String mReceiver;
			void* mUserData;

		private:
			typedef ObjectPool<Event, 10, 5> EventPool;
			static EventPool mEventPool;

			friend class ObjectPool<Event, 10, 5>;
		};

		template<class UserData>
		void Event::SetUserData(UserData* userData)
		{
			mUserData = userData;
		}

		template<class UserData>
		UserData* Event::GetUserData() const
		{
			return reinterpret_cast<UserData*>(mUserData);
		}
	}
}

#endif
